const state = {
  dict: new Map()
}
const mutations = {
  SET_DICT: (state, { key, value }) => {
    if (key !== null && key !== undefined) state.dict.set(key, value)
  },
  REMOVE_DICT: (state, key) => {
    if (state.dict.has(key)) state.dict.delete(key)
  },
  CLEAN_DICT: state => {
    state.dict.clear()
  }
}

const actions = {
  // 设置字典
  setDict({ commit }, data) {
    commit('SET_DICT', data)
  },
  // 删除字典
  removeDict({ commit }, key) {
    commit('REMOVE_DICT', key)
  },
  // 清空字典
  cleanDict({ commit }) {
    commit('CLEAN_DICT')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
